The following is code to get the client and set it up.
In [3]:
%env CLIENT bitrepository-client-1.9-RC1
!wget -Nq "https://sbforge.org/download/attachments/25395346/${CLIENT}.zip"
!unzip -quo ${CLIENT}.zip
%alias bitmag ${CLIENT}/bin/bitmag.sh %l
In [4]:
#Some imports we will need later
import random
import string
The commands presented are just examples of what the actual command to test with could look like.
Run put command on a file which is not present in the collection.
In [5]:
TESTFILE1='README.md'
Check this by running
In [6]:
%bitmag get-file-ids -c integrationtest2 -i {TESTFILE1}
The response should be
Count: Size: FileID:
Indicating that no pillar had the file. If the file is found, delete it with the following command
See https://www.safaribooksonline.com/blog/2014/02/12/using-shell-commands-effectively-ipython/ for how this works
In [7]:
hash=!cat {TESTFILE1} | md5sum - | cut -d' ' -f1
print("md5: {}".format(hash))
%bitmag delete -c integrationtest2 -i {TESTFILE1} -C {hash.s} -p "sbtape2"
%bitmag delete -c integrationtest2 -i {TESTFILE1} -C {hash.s} -p "reference2"
%bitmag delete -c integrationtest2 -i {TESTFILE1} -C {hash.s} -p "checksum2"
%bitmag delete -c integrationtest2 -i {TESTFILE1} -C {hash.s} -p "sbdisk1"
%bitmag delete -c integrationtest2 -i {TESTFILE1} -C {hash.s} -p "kbpillar2"
In [8]:
%bitmag put-file -c integrationtest2 -f {TESTFILE1}
Verify that it is now present at all pillars, and that it has the same checksum at all pillars
In [9]:
%bitmag get-file-ids -c integrationtest2 -i {TESTFILE1}
In [10]:
%bitmag get-checksums -c integrationtest2 -i {TESTFILE1}
Run put command on a file and use the file-id parameter (-i)
In [11]:
TESTFILE2=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
In [12]:
%bitmag put-file -c integrationtest2 -f {TESTFILE1} -i {TESTFILE2}
Verify that it is now present at all pillars, and that it has the same checksum at all pillars
In [13]:
%bitmag get-file-ids -c integrationtest2 -i {TESTFILE2}
In [14]:
%bitmag get-checksums -c integrationtest2 -i {TESTFILE2}
Use the URL and Checksum to put a file, already on the webdav server.
In [15]:
TESTFILE3=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
URL='http://sandkasse-01.kb.dk/dav/test.txt'
In [16]:
hash=!curl -s {URL} | md5sum - | cut -d' ' -f1
print("md5: {}".format(hash))
%bitmag put-file -c integrationtest2 -u {URL} -i {TESTFILE3} -C {hash.s}
Verify that it is now present at al pillars, with the requested checksum
In [17]:
%bitmag get-file-ids -c integrationtest2 -i {TESTFILE3}
In [18]:
%bitmag get-checksums -c integrationtest2 -i {TESTFILE3}
The putFile request should succeed.
In [19]:
%bitmag put-file -c integrationtest2 -f {TESTFILE1}
In [20]:
import hmac
import hashlib
import urllib.request
def getSaltedChecksum(url,salt,algorithm):
saltBytes = bytes.fromhex(salt)
digester = hmac.new(saltBytes,None,algorithm)
with urllib.request.urlopen(url) as from_fh:
while True:
chunk = from_fh.read()
if not chunk:
break
digester.update(chunk)
return digester.hexdigest().lower()
saltedChecksum=getSaltedChecksum(url=URL,salt='abcd',algorithm=hashlib.sha1)
print(saltedChecksum)
Use the request-checksum-algorithm and request-checksum-salt arguments (-R and -S):
In [21]:
TESTFILE4=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
Note, this will return the stored MD5 hashes, if the file is already put'et
In [22]:
hash=!curl -s {URL} | md5sum - | cut -d' ' -f1
print("md5: {}".format(hash))
%bitmag put-file -c integrationtest2 -u {URL} -i {TESTFILE4} -C {hash.s} -S 'abcd' -R HMAC_SHA1
Verify that the checksumpillar does not reply with a checksum.
In [23]:
%bitmag get-checksums -c integrationtest2 -i {TESTFILE4} -R HMAC_SHA1 -S 'abcd'
Verify that the checksumpillar and all the other pillars have the file
In [24]:
%bitmag get-file-ids -c integrationtest2 -i {TESTFILE4}
Use the request-checksum-algorithm and request-checksum-salt arguments (-R and -S):
In [25]:
TESTFILE5=''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
In [26]:
hash=!curl -s {URL} | md5sum - | cut -d' ' -f1
print("md5: {}".format(hash))
%bitmag put-file -c integrationtest2 -u {URL} -i {TESTFILE5} -C {hash.s} -R SHA1 -S 'abcd'
Verify that all the data pillars return the same checksum, and that it is identical to the previous test (where '-R HMAC_SHA1')
Use the request-checksum-algorithm and request-checksum-salt arguments (-R and no -S):
In [27]:
hash=!curl -s {URL} | md5sum - | cut -d' ' -f1
print("md5: {}".format(hash))
hash=!curl -s {URL} | sha1sum - | cut -d' ' -f1
print("sha1: {}".format(hash))
%bitmag get-checksums -c integrationtest2 -i {TESTFILE5}
Verify that the data pillars all deliver the same checksum, which must be different from the checksum in the previous two tests.
The putFile request should fail informing the user that a file with the given file ID already exists in the collection.
In [28]:
%bitmag put-file -c integrationtest2 -f .gitignore -i {TESTFILE1}
Client should fail immediately
In [29]:
%bitmag put-file -c integrationtest2 -f ThisFileDoesNotExist
Client should fail immediately
In [30]:
%bitmag put-file -c integrationtest3 -i {TESTFILE1}
Client should fail immediately
In [31]:
%bitmag put-file -c integrationtest1 -i {TESTFILE1} -p non-existing-pillar